package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DrugModelMapper;
import com.ruoyi.system.domain.DrugModel;
import com.ruoyi.system.service.IDrugModelService;

/**
 * 药品模型Service业务层处理
 * 
 * @author wmb
 * @date 2020-12-30
 */
@Service
public class DrugModelServiceImpl implements IDrugModelService 
{
    @Autowired
    private DrugModelMapper drugModelMapper;

    /**
     * 查询药品模型
     * 
     * @param id 药品模型ID
     * @return 药品模型
     */
    @Override
    public DrugModel selectDrugModelById(Long id)
    {
        return drugModelMapper.selectDrugModelById(id);
    }

    /**
     * 查询药品模型列表
     * 
     * @param drugModel 药品模型
     * @return 药品模型
     */
    @Override
    public List<DrugModel> selectDrugModelList(DrugModel drugModel)
    {
        return drugModelMapper.selectDrugModelList(drugModel);
    }

    /**
     * 新增药品模型
     * 
     * @param drugModel 药品模型
     * @return 结果
     */
    @Override
    public int insertDrugModel(DrugModel drugModel)
    {
        drugModel.setCreateTime(DateUtils.getNowDate());
        return drugModelMapper.insertDrugModel(drugModel);
    }

    /**
     * 修改药品模型
     * 
     * @param drugModel 药品模型
     * @return 结果
     */
    @Override
    public int updateDrugModel(DrugModel drugModel)
    {
        return drugModelMapper.updateDrugModel(drugModel);
    }

    /**
     * 批量删除药品模型
     * 
     * @param ids 需要删除的药品模型ID
     * @return 结果
     */
    @Override
    public int deleteDrugModelByIds(Long[] ids)
    {
        return drugModelMapper.deleteDrugModelByIds(ids);
    }

    /**
     * 删除药品模型信息
     * 
     * @param id 药品模型ID
     * @return 结果
     */
    @Override
    public int deleteDrugModelById(Long id)
    {
        return drugModelMapper.deleteDrugModelById(id);
    }


    @Override
    public List<Map<String, Object>> drugModelStat() {
        return drugModelMapper.drugModelStat();
    }

    @Override
    public DrugModel selectDrugModel(Integer type, String drugName) {

        DrugModel drugModel = new DrugModel();
        drugModel.setType(type);
        drugModel.setCorpusSource(drugName);
        List<DrugModel> drugModels = drugModelMapper.selectDrugModelList(drugModel);
        if(drugModels != null && !drugModels.isEmpty()){
            return drugModels.get(0);
        }
        return null;
    }
}
